package com.gomokult.utility;

import java.sql.*;
import java.util.Scanner;
//赵哲群
public class JDBCUtil {
    public static Connection con = null;
    public static Statement stat = null;
    public static PreparedStatement pstat = null;
    public static Scanner sc =null;
    public static ResultSet rs = null;
    static {//在静态代码块中进行数据库连接
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (Exception e) {
            e.printStackTrace();
        }
        String url =
                "jdbc:mysql://localhost:3306/gomokult?" +
                        "useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8";
        String user = "root";
        String password = "";//密码自填
        try {
            con = DriverManager.getConnection(url, user, password);   //连接代码
        }
        catch (SQLException e) {
            System.out.println(e);
            System.exit(-1);
        }
    }
    public static void close() throws SQLException {
        if(con!=null)
            con.close();
        if(stat!=null)
            stat.close();
        if(pstat!=null)
            pstat.close();
    }
}
